package org.example.mouse;

import com.sun.jna.Library;
import com.sun.jna.Native;
import java.awt.MouseInfo;
import java.awt.Point;

public class SmoothMouseMovement {

    public interface MouseDriver extends Library {
        MouseDriver INSTANCE = Native.load("./MouseControl.dll", MouseDriver.class);
        void move_Abs(int x, int y);
    }

    public static void linearInterpolation(int xEnd, int yEnd, int numSteps, double delay) {
        Point startPoint = MouseInfo.getPointerInfo().getLocation();
        double startX = startPoint.getX();
        double startY = startPoint.getY();

        double dx = (xEnd - startX) / numSteps;
        double dy = (yEnd - startY) / numSteps;

        for (int i = 1; i <= numSteps; i++) {
            int nextX = (int) Math.round(startX + dx * i);
            int nextY = (int) Math.round(startY + dy * i);

            MouseDriver.INSTANCE.move_Abs(nextX, nextY);

            try {
                Thread.sleep((long) (delay * 1000));
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                return;
            }
        }
    }

    public static void main(String[] args) {
        while (true) {
            try {
                Thread.sleep(2000); // Wait 2 seconds

                int xEnd = 30;
                int yEnd = 30;

                linearInterpolation(xEnd, yEnd, 20, 0.01);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }

    }
}